package com.sg.service.biz.framework.impl;

import com.sg.common.util.RedisUtil;
import com.sg.entity.Users;
import com.sg.service.base.framework.MUsersService;
import com.sg.common.exception.Assert;
import org.apache.skywalking.apm.toolkit.trace.Tag;
import org.apache.skywalking.apm.toolkit.trace.Tags;
import org.apache.skywalking.apm.toolkit.trace.Trace;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * @author ：
 * @version 1.0
 * @date ：
 */
@Service
public class PasswordServiceImpl
        implements com.wicket.okrframework.biz.service.PasswordService {

    @Resource
    private RedisUtil redisUtil;
    @Resource
    private MUsersService mUsersService;

    /**
     * D1-2修改密码[1158]
     * gen by moon at 8/10/2022, 3:14:46 AM
     */
    @Trace(operationName = "D1-2修改密码")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    @Transactional(rollbackFor = Exception.class)
    @Override
    public UpdateChangePasswordRespDto updateChangePassword(UpdateChangePasswordReqDto reqDto) {


        //步骤0: 1-2-01修改个人账号 - updateUser
        boolean bOOLEAN;
        Users users = new Users();
        if (reqDto != null) {
            users.setUserId(reqDto.getUserId());//sourceId:24935_1
            users.setPassword(reqDto.getPassword());//sourceId:24937_1
            users.setPhone(reqDto.getPhone());//sourceId:27003_1
        }

        /*1-2-01修改个人账号[46]   */
        Assert.isNull(users.getUserId(), "D1-2修改密码-1-2-01修改个人账号-个人账号不能为空", false);
        bOOLEAN = mUsersService.updateUser(users);


        UpdateChangePasswordRespDto retData = new UpdateChangePasswordRespDto();


        return retData;
    }

    /**
     * D1-2修改密码(公共)[1158]
     * gen by moon at 10/1/2022, 11:59:39 PM
     */
    @Trace(operationName = "D1-2修改密码(公共)")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    @Transactional(rollbackFor = Exception.class)
    @Override
    public ChangePasswordComRespDto changePasswordCom(ChangePasswordComReqDto reqDto) {


        //步骤0: 1-2-01修改个人账号 - updateUser
        boolean bOOLEAN;
        Users users = new Users();
        if (reqDto != null) {
            users.setUserId(reqDto.getUserId());//SimpleFieldAssign//sourceId:24935_1
            users.setPassword(reqDto.getPassword());//SimpleFieldAssign//sourceId:24937_1
            users.setPhone(reqDto.getPhone());//SimpleFieldAssign//sourceId:27003_1
        }

        /*1-2-01修改个人账号[46]   */
        Assert.isNull(users.getUserId(), "D1-2修改密码(公共)-1-2-01修改个人账号-个人账号不能为空", false);
        bOOLEAN = mUsersService.updateUser(users);


        ChangePasswordComRespDto retData = new ChangePasswordComRespDto();


        return retData;
    }
    //
}
